package com.lin.reggie.mapper;

import com.lin.reggie.dto.SetmealDto;
import com.lin.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface SetMealMapper {

    @Select("select count(*) from setmeal where category_id = #{cid}")
    Integer findByCid(long cid);

    //查看套餐
    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status} and is_deleted=0")
    List<Setmeal>findSetmeal(@Param("categoryId") Long categoryId,
                             @Param("status")Integer status);

    /**
     * 添加套餐
     *
     */
    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status}" +
            ",#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser}" +
            ",#{updateUser},0)")
    @Options(useGeneratedKeys = true ,keyProperty = "id",keyColumn = "id")
    void save(SetmealDto setmealDto);

    //根据名字查找套餐
    List<Setmeal>findByName(@Param("name") String name);

    //查找指定id列表数据中含有启用套餐数据的个数
    Integer countByIds(@Param("ids") List<Long> ids);

    //删除指定多个ID的套餐（伪删除）
    Integer deleteByIds(@Param("ids") List<Long> ids,
                        @Param("updateUser") Long updateUser,
                        @Param("updateTime") LocalDateTime updateTime);
}
